package com.jerry.controller;

import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import org.joda.time.DateTime;
import org.joda.time.Days;
import org.joda.time.LocalDate;
import org.joda.time.Period;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.*;

/**
 * Created by Shirly on 2016/8/25.
 */
public class Ycontroller {

    public boolean isAfterPayDay(DateTime datetime) {
        if (datetime.getMonthOfYear() == 2) {   // February is month 2!!
            return datetime.getDayOfMonth() > 26;
        }
        return datetime.getDayOfMonth() > 28;
    }

    public Days daysToNewYear(LocalDate fromDate) {
        LocalDate newYear = fromDate.plusYears(1).withDayOfYear(1);
        return Days.daysBetween(fromDate, newYear);
    }

    public boolean isRentalOverdue(DateTime datetimeRented) {
        Period rentalPeriod = new Period().withDays(2).withHours(12);
        return datetimeRented.plus(rentalPeriod).isBeforeNow();
    }

    public String getBirthMonthText(LocalDate dateOfBirth) {
        return dateOfBirth.monthOfYear().getAsText(Locale.ENGLISH);
    }
    public static void main(String[] args) {
//        String[] abc = new String[] { "abc", "acd", "add" };
//        String[] abd = new String[] {"acd", "cd", "de"};
//
//        List<String> abcList =new ArrayList<String>(Arrays.asList(abc)) ;
//        List<String> abdList = new ArrayList<String>(Arrays.asList(abd));
//
//        System.out.println(abcList.retainAll(abdList));
//        System.out.println(abcList);

        try {
            byte[] b_gbk = "中".getBytes("GBK");
            byte[] b_utf8 = "中".getBytes("UTF-8");
            byte[] b_iso88591 = "中".getBytes("ISO8859-1");

            String s_gbk = new String(b_gbk,"GBK");
            String s_utf8 = new String(b_utf8,"UTF-8");
            String s_iso88591 = new String(b_iso88591,"ISO8859-1");
//          String s_iso885912 =new String("中".getBytes("UTF-8"),"ISO8859-1");
//          String ss_iso885912 = new String(s_iso885912.getBytes("ISO8859-1"),"UTF-8");

            String s_iso885912 =new String("中".getBytes("GBK"),"ISO8859-1");
            String ss_iso885912 = new String(s_iso885912.getBytes("ISO8859-1"),"GBK");


            System.out.println(s_gbk);
            System.out.println(s_utf8);
            System.out.println(s_iso88591);
            System.out.println(ss_iso885912);

            BigDecimal a = new BigDecimal(1.5);
            System.out.println("down="+a.setScale(0,BigDecimal.ROUND_HALF_DOWN)+"/tup="+
                    a.setScale(0,BigDecimal.ROUND_HALF_UP));

            double d =538.8;
            System.out.println(d*100);
            System.out.println(d *10 *10);
            BigDecimal a1 = new BigDecimal(Double.toString(d));
            BigDecimal b1 = new BigDecimal(Double.toString(100));
            BigDecimal result = a1.multiply(b1);// 相乘结果
            System.out.println(result);
            BigDecimal one = new BigDecimal("1");
            BigDecimal e = result.divide(one,BigDecimal.ROUND_HALF_UP);//保留1位数
            System.out.println(e);

            Ycontroller test =  new Ycontroller();
            System.out.println(test.isAfterPayDay(new DateTime()));

            DateTime dateTime=new DateTime(2012, 12, 15, 18, 23,55);
            System.out.println(dateTime);

            DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");

            //时间解析
            DateTime dateTime1 = DateTime.parse("2012-12-21 23:22:45", format);

            //时间格式化，输出==> 2012/12/21 23:22:45 Fri
            String string_u = dateTime1.toString("yyyy/MM/dd HH:mm:ss EE");
            System.out.println(string_u);

            //格式化带Locale，输出==> 2012年12月21日 23:22:45 星期五
            String string_c = dateTime1.toString("yyyy年MM月dd日 HH:mm:ss EE",Locale.CHINESE);
            System.out.println(string_c);


        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    }
}
